package com.prawn.authority.utils;

import entity.PageResult;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页工具类
 * @param <T>
 */
public class PageUtil<T> {

	public static <T> PageResult<T> getPage(List<T> list, int page, int size) {
		if (page == 0 || size == 0 || list == null || list.size() == 0) {
			return new PageResult<T>((long)(list==null?0:list.size()), list);
		}
		List<T> records = new ArrayList<>();
		for (int i = (page - 1) * size; i < page * size && i < list.size(); i++) {
			records.add(list.get(i));
		}
		return new PageResult<T>((long) list.size(), records);
	}
}
